package com.ximcontroller.models;

import java.util.Collection;
import java.util.HashMap;
import java.util.Observable;

import com.ximcontroller.models.elements.*;

public class Workspace extends Observable implements java.io.Serializable
{
	static final long serialVersionUID = 200911271931L;
	
	private int id;
	private String name;
	private String description;
	
	
	private HashMap<Integer, Project> projects;
	private HashMap<Integer, Element> elements;
	
	//Temporal dirty thing
	private XIM machine;
	
	public Workspace()
	{
		this.projects = new HashMap<Integer, Project>();
	}
	
	public int getID()
	{
		return this.id;
	}
	
	public void setID(int id)
	{
		this.id = id;
		this.notifyObservers();
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public void setName(String name)
	{
		this.name = name;
		this.notifyObservers();
	}
	
	public String getDescription()
	{
		return this.description;
	}
	
	public void setDescription(String description)
	{
		this.description = description;
		this.notifyObservers();
	}
	
	public void addElement(Element m)
	{
		this.elements.put(m.getID(), m);
		this.notifyObservers();
	}
	
	public void removeElement(int id)
	{
		this.elements.remove(id);
		this.notifyObservers();
	}
	
	public Collection<? extends Element> listElements()
	{
		return this.elements.values();
	}
	
	public Element getElement(int id)
	{
		return (this.elements.get(id));
	}
	
	public void addProject(Project p)
	{
		this.projects.put(p.getID(), p);
		this.notifyObservers();
	}
	
	public void removeProject(int id)
	{
		this.projects.remove(id);
		this.notifyObservers();
	}
	
	public Project getProject(int id)
	{
		return this.projects.get(id);
	}
	
	public Collection<Project> listProjects()
	{
		return this.projects.values();
	}
	
	public void getXIM()
	{
		
	}

	public XIM getMachine()
	{
		return machine;
	}

	public void setMachine(XIM machine)
	{
		this.machine = machine;
	}
}
